package com.xianyun.book.domain.price;

import com.alibaba.cola.exception.SysException;

/**
 * 货币配置
 * @author macos-zyj
 */
public enum CurrencyEnum {
    /**CNY*/
    CNY(1.0,"CNY"),
    /**元*/
    CN(1.0,"元"),
    /**JPY*/
    JPY(0.05887,"JPY"),
    /**新台币*/
    TW(0.22727,"新台币"),
    /**TWD*/
    NT$(0.22727,"NT$"),
    /** NTD */
    NTD(0.22727,"NTD"),
    /** USD*/
    USD(6.4367,"USD"),
    /** HK$*/
    HK$(0.8286," HK$"),
    ;

    Double changeRate;
    String currencyType;

    CurrencyEnum(Double changeRate, String currencyType) {
        this.changeRate = changeRate;
        this.currencyType = currencyType;
    }

    public static Double getChangeRateByType(String currencyType){
        if ("".equals(currencyType)){
            return 1.0;
        }
        for (CurrencyEnum currency:values()){
            if (currencyType.equals(currency.currencyType)){
                return currency.changeRate;
            }
        }
        throw new SysException("请检查货币配置");
    }
}
